package com.h5ve.web.task;

import cn.hutool.core.util.RuntimeUtil;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 数据库备份定时任务
 *
 * @author tumengtech
 * @date 2019-06-28
 */
@Slf4j
@Component("backupTask")
public class BackupTask {

    private String userName = "root";
    private String password = "root";
    private String dbName = "h5ve-boot";

    @SneakyThrows
    public void runTask() {
        log.info("数据库备份定时任务 ", new Date());
        String cmd = "mysqldump -u" + userName + " -p" + password + " " + dbName + " | gzip > /opt/backup/" + dbName + ".sql.gz";
        RuntimeUtil.exec(new String[]{"/bin/sh", "-c", cmd});
    }
}
